/**************************************************************
  > File Name: 1.c
  > Author: LuoLiang
  > Mail: 1204553475@qq.com 
  > Created Time: 2022年03月01日 星期二 07时09分08秒
 **************************************************************/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>

#define BUFSIZE 128
#define N 6
#define SIZE 18

void *func(void *argc)
{
	int i, j, len;
	int count;
	char *buf = (char *)argc;
	
	len = strlen(buf);
	printf("\033[2J");

	while (1)
	{
		for (j = 0; j < len; j += 3)
		{
			count = SIZE;
			printf("\033[10;40H");
			for (i = j; i < len && (i - j) < 3*N; i++)
			{
				printf("%c",buf[i]);
			}

			fflush(stdout);
			usleep(700000);	
			printf("\033[10;40H");
			while (count--)
				printf(" ");
			pthread_testcancel();
		}
	}
}


int main(int argc, char **argv)
{
	pthread_t tid;
	char buf[BUFSIZE] = "我草你妈崔俊.mp3";
	char buf1[BUFSIZE] = "你一定能够成为你想要.mp3";
	char buf2[BUFSIZE] = "收款方老师发的.mp3";
	char ch;

	pthread_create(&tid, NULL, func, (void *)buf);
	while (1)
	{
		ch = getchar();
		if (ch == 'w')
		{
			pthread_cancel(tid);
			pthread_create(&tid, NULL, func, (void *)buf1);
		}
		if (ch == 's')
		{
			pthread_cancel(tid);
			pthread_create(&tid, NULL, func, (void *)buf2);
		}
	}
    exit(0);
}
